import {
    isVoid,
    isNotVoid,
    isVoidArg,
    isNotVoidArg,
    calcAnnualizedByTerminationPaymentDate,
    isEquativesABC,
    isEquativesAnnualizedABC,
    isEqualNum,
    mulArg,
    round,
} from '@/utils/util'
import _ from 'lodash'
const onStrikeChange = (form) => {
    let a = form.data.strike
    if (Boolean(form.data.spotPrice)) {
        form.data.strikePercentage = 0
    }
    if (isNotVoid(String(form.data.spotPrice))) {
        form.data.strikePercentage = _.multiply(_.divide(a, form.data.spotPrice), 100)
        return
    }
}

const onStrikePercentageChange = (form) => {
    let a = form.data.strikePercentage
    if (isNotVoid(String(form.data.spotPrice))) {
        form.data.strike = _.multiply(_.divide(a, 100), form.data.spotPrice)
        return
    }
}


/**
 * 2.4
 * 低行权比例  联动  期初价格 行权价
 *  修改行权价
 * */
const onLowStrikePercentageChange = (form) => {
    let newValue = form.data.lowStrikePercentage
    if (isVoid(String(newValue))) {
        return
    }
    if (strikeLinkValid(form.data.spotPrice, newValue, form.data.lowStrike)) {
        return
    }
    if (isNotVoid(String(newValue))) {
        if (isNotVoid(String(form.data.spotPrice))) {
            if (Number(form.data.spotPrice) == 0) {
                form.data.lowStrike = 0
                return
            }
            form.data.lowStrike = form.data.spotPrice * newValue / 100
            return
        }
    }
}
/**
 * 2.5
 *  行权价  联动  期初价格 行权比例
 *  修改行权比例
 * */
const onLowStrikeChange = (form) => {
    let newValue = form.data.lowStrike
    if (isVoid(String(newValue))) {
        return
    }
    if (strikeLinkValid(form.data.spotPrice, form.data.lowStrikePercentage, newValue)) {
        return
    }
    if (isNotVoid(String(newValue))) {
        if (isNotVoid(String(form.data.spotPrice))) {
            if (Number(form.data.spotPrice) == 0) {
                form.data.lowStrikePercentage = 0
                return
            }
            form.data.lowStrikePercentage = newValue / form.data.spotPrice * 100
            return
        }
    }
}


/**
 * 2
 *  行权价  期初价格 行权比例 联动  等式
 *
 * */
function strikeLinkValid(spotPrice, strikePercentage, strike) {
    if (isNotVoid(spotPrice) && isNotVoid((strikePercentage)) && isNotVoid(strike)) {
        return isEquativesABC(spotPrice, strikePercentage / 100, strike)
    }
    return false
}
export {
    onStrikeChange,onStrikePercentageChange,onLowStrikePercentageChange,onLowStrikeChange,strikeLinkValid
}